package com.helmlabs.grouper.finance.dao;

import java.util.Date;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.helmlabs.grouper.finance.model.MembershipDueSchedule;

public class MembershipDueDaoHibernate extends HibernateDaoSupport implements MembershipDueDao {

	public MembershipDueSchedule getSchedule(Long id) {
		return (MembershipDueSchedule)getHibernateTemplate().get(MembershipDueSchedule.class, id);
	}
	
	public MembershipDueSchedule getSchedule(Date request){
		DetachedCriteria criteria = DetachedCriteria.forClass(MembershipDueSchedule.class);
		criteria.add(Restrictions.ge("endOfferingOn", request)).add(Restrictions.lt("beginOfferingOn", request));
		List schedules = getHibernateTemplate().findByCriteria(criteria);
		if (schedules!=null && schedules.size()>0)
			return (MembershipDueSchedule)schedules.get(0);
		return null;
	}

}
